//
//  AppDelegate.m
//  MyChatDemo
//
//  Created by DragonYao on 2017/9/8.
//  Copyright © 2017年 DragonYao. All rights reserved.
//

#import "AppDelegate.h"
#import "DDLog.h"
#import "DDTTYLogger.h"

@interface AppDelegate ()

@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    SLog(@"%@", [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject]);
    //打开XMPP的跟踪日志
    DDTTYLogger *ddttylog = [DDTTYLogger sharedInstance];
    ddttylog.colorsEnabled = YES;
//    [DDLog addLogger:ddttylog];
    if ([UserLocalInfo sharedUserInfo].hasLogin) {
        UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
        self.window.rootViewController = [storyboard instantiateInitialViewController];
    
        //当用户已经登陆过，那么退出后台，与服务器的连接就会断，需要自动连接，获取数据
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{//延迟一秒等待tabbarVC加载完成
            [[XMPPManager sharedManager] userLogin:^(XMPPResultType type) {
                //视情况而定，需不需要处理
            }];
        });
    }
    
    /**
     *  注册通知
     */
    UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound|UIUserNotificationTypeAlert| UIUserNotificationTypeBadge) categories:nil];
    [application registerUserNotificationSettings:settings];
    
    return YES;
}


- (void)applicationWillResignActive:(UIApplication *)application {
   
}


- (void)applicationDidEnterBackground:(UIApplication *)application {
    
}


- (void)applicationWillEnterForeground:(UIApplication *)application {
    
}


- (void)applicationDidBecomeActive:(UIApplication *)application {
    
}


- (void)applicationWillTerminate:(UIApplication *)application {
    
}

@end
